import SwiftUI

struct CreateView: View {
    @State private var selectedType: TaskType = .body
    @State private var taskName = ""
    @State private var taskDescription = ""
    @State private var duration = 30
    @State private var showingTimePicker = false
    
    var body: some View {
        NavigationView {
            Form {
                Section {
                    Picker("修炼类型", selection: $selectedType) {
                        ForEach(TaskType.allCases, id: \.self) { type in
                            Text(type.rawValue).tag(type)
                        }
                    }
                    
                    TextField("任务名称", text: $taskName)
                    TextField("任务描述", text: $taskDescription)
                    
                    HStack {
                        Text("持续时间")
                        Spacer()
                        Text("\(duration)分钟")
                            .foregroundColor(.secondary)
                    }
                    .contentShape(Rectangle())
                    .onTapGesture {
                        showingTimePicker = true
                    }
                }
                
                Section {
                    Button(action: {
                        // 创建任务
                    }) {
                        Text("创建任务")
                            .frame(maxWidth: .infinity)
                            .foregroundColor(.white)
                            .padding()
                            .background(taskName.isEmpty ? Color.gray : selectedType.color)
                            .cornerRadius(8)
                    }
                    .disabled(taskName.isEmpty)
                }
            }
            .navigationTitle("创建任务")
            .sheet(isPresented: $showingTimePicker) {
                NavigationView {
                    Picker("持续时间", selection: $duration) {
                        ForEach([15, 30, 45, 60, 90, 120], id: \.self) { mins in
                            Text("\(mins)分钟").tag(mins)
                        }
                    }
                    .pickerStyle(.wheel)
                    .navigationTitle("选择时长")
                    .navigationBarItems(
                        trailing: Button("完成") {
                            showingTimePicker = false
                        }
                    )
                }
            }
        }
    }
}

